package com.xichen.config;

import com.xichen.config.interceptor.UserInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;

/**
 * @author tang wei
 * @version 1.0
 * @date 2020/7/18 12:21
 */
@Component
public class WebConfigurer implements WebMvcConfigurer {
    @Autowired
    private UserInterceptor userInterceptor;

    @Override
    public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) {

    }

    /**
     * 配置需要拦截的请求，与需要放行的请求
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //拦截请求
        registry.addInterceptor(userInterceptor).addPathPatterns("/**").excludePathPatterns(
                //放行请求
                "/user/login",//登录请求
                "/cold/getCold",//验证码请求
                "/**/index.html",//登录页面
                "/**/*.js",   //js静态资源
                "/**/*.css", //css静态资源
                "/**/*.woff",//woff资源
                "/**/*.ttf"//ttf资源
        );
    }
}
